﻿import mx.utils.Delegate;
/**
 * ...
 * @author sminutoli
 */

import com.dmotiko.lib.*
 
class TimerMovie {
	
	public static function createTimer( root:MovieClip ):MovieClip {
		if ( ! root ) root = _root;
		var sName:String = "timer";
		var nCount:Number = 0;
		while ( root[sName + nCount] ) {
			nCount++;
		}
		var timer = root.createEmptyMovieClip(sName+nCount, root.getNextHighestDepth() );
		timer.startTimer = function( args ) {
			var nTime:Number = getTimer();
			this.onEnterFrame = function(){
				if ( getTimer() - nTime >= args.delay) {
					this.onEnterFrame = null;
					Delegate.create( args.bind, args.listener )();
				}
			}
		}
		timer.stopTimer = function() {
			delete this.onEnterFrame;
		}
		return timer;
	}
	
}